/*
 * scheduler.c
 *
 *  Created on: 2023.02.21
 *      Author: Lw
 */
#include "scheduler.h"
#include "platform.h"
#include "update_firmware.h"
#include "tele_data_transfer.h"
#include "camera_process.h"
#include "gnc_addit.h"
#include "cali_panel.h"
#include "pl_comm.h"
#include "fpga_reg.h"
#include "sys_monitor.h"
#include "admin_firmware.h"

static void scheduler_10hz(void);
static void scheduler_50hz(void);
static void scheduler_100hz(void);
static void scheduler_500hz(void);
static void scheduler_1khz(void);
static void scheduler_2khz(void);

extern volatile S_UTCTime s_tUTCTime;
void app_initial(void)
{
    u8 iStatus = 0;
    iStatus = CameraParaInit(1);//相机1参数初始化
    g_tEquipmentStatus.equipInitStatus|=(iStatus << 5);
    iStatus =  CameraParaInit(2);//相机2参数初始化
    g_tEquipmentStatus.equipInitStatus|=(iStatus << 6);
    iStatus =  updateFirmwareInit();
	g_tEquipmentStatus.equipInitStatus|=(iStatus << 7);
	iStatus =  caliDataInit();
	g_tEquipmentStatus.caliInitStatus = iStatus;
    g_tEquipmentStatus.yw2Version = YW2_PREP_VERSION;
    adminFirmwareInit();
    plCommInit();
    gncAdditInit();
    sysMonitorInit();
	platform_enable_interrupts();
}


static void scheduler_10hz(void)
{
	caliDataProcess();
}

static void scheduler_50hz(void)
{

}

static void scheduler_100hz(void)
{
    CameraProcessUpdate();
}

static void scheduler_500hz(void)
{

}

static void scheduler_1khz(void)
{

}

static void scheduler_2khz(void)
{
	updataUTCtime();
}

static void scheduler_1hz(void)
{
	prepParamSave();
	SysParamSave();
	wdtFeedProcess();
	adminFirmwareProcess();
	xil_printf("TimeS = %d,TimeMs = %d TESE FW\n\r", s_Addit1Data.ShootMomentS,s_Addit1Data.ShootMomentMs);
	xil_printf("AdditTotalCount = %d\n\r", s_Addit1Data.AdditTotalCount);

//	can_config();
    PixelMask_Config();
}

static u16 BaseTime2KhzCounter = 0;
void scheduler(void)
{
    updateFirmwareProcess();

	while(GetBaseTime2khzScheduler())
	{
		BaseTime2KhzCounter ++;
		BaseTime2KhzCounter = BaseTime2KhzCounter >= 2000 ? 0 : BaseTime2KhzCounter;
		scheduler_2khz();
		if(BaseTime2KhzCounter % 2 == 1)
		{
			scheduler_1khz();
		}
		if(BaseTime2KhzCounter % 4 == 1)
		{
			scheduler_500hz();
		}
		if(BaseTime2KhzCounter % 20 == 1)
		{
			scheduler_100hz();
		}
		if(BaseTime2KhzCounter % 40 == 1)
		{
			scheduler_50hz();
		}
		if(BaseTime2KhzCounter % 200 == 1)
		{
			scheduler_10hz();
		}
		if(BaseTime2KhzCounter % 1999 == 1)
		{
			scheduler_1hz();
		}
	}
    CameraBurstShootProcess();
	gncAdditProcess();
}


